<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;

class BaseController extends Controller
{
    public function success(array $data = [],int $code = 1, string $msg = 'success')
    {
        return $this->result($code, $msg, $data);
    }

    public function result(int $code, string $msg = 'OK', array $data = [], int $httpStatus = 200)
    {
        $result = array(
            'code' => $code,
            'msg' => $msg,
            'data' => $data
        );
        return response()->json($result, $httpStatus);
    }

    public function fail(string $msg = 'fail', array $data = [], int $code = 0)
    {
        return $this->result($code, $msg, $data);
    }

}
